<?php

/**
 * Description of WrapperApp
 *
 * @author EaDeveloper
 */
class AppSecurity implements EaSoftModule {

    public $instanceName = "AppSecurity";
    public $db;
    public $includePath;

    public function getCssFiles() {
?>
        <link href="<?php echo RELATIVE_PATH; ?>css/security.css" rel="stylesheet" type="text/css" />
<?php
    }

    public function getJsFiles() {

    }

    public function getWindowTitle() {
        return "Seguridad";
    }

    public function usuarioValido() {
        $this->db=  DbManager::getMe();
        $boSec=BoSecurity::getMe();
        if (!isEmpty(getParam("usuario")) && !isEmpty(getParam("clave"))) {
            $r = $this->db->queryToArray(sprintf("select * from cllg_user where USER_NAME='%s' and PASSWORD='%s' ",
                                    getParam("usuario"), md5(getParam("clave"))));
            if (count($r) > 0) {
                $_SESSION[USUARIO] = array("usuario" => getParam("usuario"));                
                $boSec->registrarAccion( "Ingreso al sistema!",  "Ha iniciado session correctamente"); 
                return true;
            } else {
                $_SESSION["ERROR"] = "Clave o Usuario invalidos!";
                $boSec->registrarAccion( "Intento fallido de ingresar!",  "Ocurrio error cuando intento ingrear al sistema"); 
            }
        } else {
            $_SESSION["ERROR"] = "Datos Incompletos!";
        }
        return false;
    }

    public function main() {
        include MODULES . DS . "security/main.php";
    }

}
?>
